# 静态方法可以直接通过类名调用
class_name StringUtil

# 常量
const GRAVITY := 9.8

# 静态方法 - 计算两点间距离
static func distance(point1: Vector2, point2: Vector2) -> float:
	return point1.distance_to(point2)

# 静态方法 - 生成随机颜色
static func random_color() -> Color:
	return Color(randf(), randf(), randf())

#读取文件到字符串中
static func read_file_to_string(path: String) -> String:
	if FileAccess.file_exists(path):
		var file = FileAccess.open(path, FileAccess.READ)
		var content = file.get_as_text()
		file.close()
		return content
	else:
		push_error("File not found: " + path)
		return ""


#根据文件路径加载json字符串并转成字典返回
static func read_file_to_Dic(path: String) -> Dictionary:
	var file = FileAccess.open(path, FileAccess.READ)
	if file == null:
		push_error("Failed to load JSON file: " + path)
		return {}
	
	var json = JSON.new()
	var result = json.parse(file.get_as_text())
	if result != OK:
		push_error("JSON parse error: " + json.get_error_message())
		return {}
		
	return json.get_data()

#根据文件路径加载json字符串并转成字典返回
static func read_file_to_Array(path: String) -> Array:
	var file = FileAccess.open(path, FileAccess.READ)
	if file == null:
		push_error("Failed to load JSON file: " + path)
		return []
	
	var json = JSON.new()
	var result = json.parse(file.get_as_text())
	if result != OK:
		push_error("JSON parse error: " + json.get_error_message())
		return []
		
	return json.get_data()
